<?php

namespace app\controller\wmapi\management;

use App\Library\Y;
use app\model\DcdSpecsCans;
use app\model\WaAdmins;
use app\model\WaOrdersQuotationRelevance;
use app\model\WaProducts;
use app\model\WpProductsCans;
use app\controller\wmapi\IndexController;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use plugin\admin\app\common\Util;
use plugin\admin\app\controller\Crud;
use plugin\admin\app\model\User;
use support\Request;
use support\Response;
use Tinywan\Validate\Validate;
use Workerman\Worker;


class WpProductCansController extends Validate
{
    /**
     * 车型数据列表 -分页
     * @param Request $request
     * @return Response
     */
    public function specsMassageList(Request $request)
    {
        $param = $request->all();
        $page = page($param['page']);
        $pageNum = pageNum($param['pageNum']);
        $fields = ['*'];
        $condition = [];
        if ($param['id']) {
            $condition [] = ['id' => $param['id']]; // id
        }

        if ($param['series_name']) {
            $condition [] = ['series_name', 'like', '%' . $param['series_name'] . '%']; // 车系名称
        }

        if ($param['car_name']) {
            $condition [] = ['car_name', 'like', '%' . $param['car_name'] . '%']; // 车型名称
        }

        if ($param['sub_brand_name']) {
            $condition [] = ['sub_brand_name', 'like', '%' . $param['sub_brand_name'] . '%']; // 品牌名称
        }

        if ($param['series_type']) {
            $condition [] = ['series_type', 'like', '%' . $param['series_type'] . '%']; // 车系分类  car SUV  MPV
        }

        $res = WpProductsCans::list($page, $pageNum, $fields, $condition);
        return IndexController::successed($res, '数据列表');
    }

    /**
     * 车型数据列表 -不分页
     * @param Request $request
     * @return Response
     */
    public function specsMassageAll(Request $request)
    {
        $param = $request->all();
        $fields = ['car_name', 'series_name','sub_brand_name','series_type','sub_brand_name','market_time','car_year'];
        $condition = [];
        if ($param['car_name']) {
            $condition [] = ['car_name', 'like', '%' . $param['car_name'] . '%']; // 车型名称
        }
        $res = WpProductsCans::all($fields, $condition);
        return IndexController::successed($res, '数据列表');
    }

    /**
     * 车型数据详情信息
     * @param Request $request
     * @return Response
     */
    public function specsMassageDetail(Request $request){

        $param = $request->all();
        $fields = ['*'];
        $condition = [];
        $condition = [];
        if (array_key_exists('id',$param)){
            if ($param['id']) {
                $condition [] = ['id', '=', $param['id']]; //
            }
        }

//        if (array_key_exists('car_name',$param)){
//            if ($param['car_name']) {
//                $condition [] = ['car_name', 'like', '%' . $param['car_name'] . '%']; // 车型名称
//            }
//        }

        $res = WpProductsCans::find($fields, $condition);

        return IndexController::successed($res, '车型数据列表');
    }

}